package com.zimmur.service.impl.designer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zimmur.common.AppModuleEnum;
import com.zimmur.dao.designer.IDesignerFavDao;
import com.zimmur.model.account.view.ConcernView;
import com.zimmur.model.base.AdBanner;
import com.zimmur.model.desiger.DesigerFav;
import com.zimmur.model.desiger.view.DesigerInfoVo;
import com.zimmur.service.base.IAdBannerService;
import com.zimmur.service.designer.IDesignerFavService;
import com.zimmur.tools.PageUtil;


@Service("designerFavService")
public class DesignerFavServiceImpl implements IDesignerFavService{
	@Resource
	private IDesignerFavDao designerFavDao;
	@Resource
	private IAdBannerService adBannerService;

	@Override
	public DesigerFav selectDesigerFav(long createUserId, long userId) {
		
		return designerFavDao.selectDesigerFav(createUserId, userId);
	}

	@Override
	public int updateDesigerFav(DesigerFav desigerFav) {
		
		return designerFavDao.updateDesigerFav(desigerFav);
	}

	@Override
	public int insertDesigerFav(DesigerFav desigerFav) {
		
		return designerFavDao.insertDesigerFav(desigerFav);
	}

	@Override
	public int countByCreateUserId(long createUserId) {
		
		return designerFavDao.countDesignerFavByCreateUserId(createUserId);
	}
	@Override
	public PageUtil<ConcernView> selectDesigerByDesigerFav(long createUserId,int pageNo) {
		PageUtil<ConcernView> page=new PageUtil<>();
		
		if(pageNo==0){
			pageNo=1;
		}
		
		int totalRecord=countByCreateUserId(createUserId);
		page.setTotalRecord(totalRecord);
		page.setPageNo(pageNo);
		if(totalRecord>0){
			List<ConcernView> concernViews=designerFavDao.selectDesigerByDesignerFav(createUserId, page.getPageBeginNo(), page.getPageSize());
			page.setItemList(concernViews);
		}
		
		return page;
	}

	@Override
	public Map<String, Object> selectConcernIndex(long createUserId) {
		Map<String, Object> map=new HashMap<>();
		List<AdBanner> adBannerList = adBannerService.selectAdList(Integer.parseInt(AppModuleEnum.ClothsMaker.getModuleId()));
		if(adBannerList!=null && adBannerList.size() > 0){
			map.put("adBannerList", adBannerList);
		}else{
			map.put("adBannerList", new ArrayList<>());
		}
		PageUtil<ConcernView> page=selectDesigerByDesigerFav(createUserId, 1);
		map.put("concernList", page);
		return map;
	}

}
